<template>
  <ContentDetailWrap>
    <template #header>
      <BaseButton @click="go(-1)">
        {{ t('common.back') }}
      </BaseButton>
      <BaseButton :disabled="!shopTableList.length" type="primary" @click="handleDelivery(1)">
        {{ t('order.delivery') }}({{ t('order.nonVirtualWarehouse') }})
      </BaseButton>
    </template>
    <div class="w-full flex justify-between">
      <div class="w-85%">
        <!--  主内容-->
        <div class="flex my-20px text-14px">
          <span class="font-bold">当前审核节点：</span>
          <span>{{ useEnumeratePicker(reviewNodeList, form.review_node) }}</span>
        </div>
        <!--    展示字段-->
        <Descriptions :schema="descriptionSchema" :data="form" />
        <!--    商品信息-->
        <div class="flex flex-items-center my-20px text-14px font-bold">商品信息</div>
        <el-table
          :data="shopTableList"
          highlight-current-row
          stripe
          border
          ref="tableRef"
          :cell-style="{ textAlign: 'center' }"
          :header-cell-style="{ textAlign: 'center' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" :selectable="selectable" width="55" />
          <el-table-column
            :label="t('wholesalOrder.warehouse')"
            min-width="150"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(warehouseList, row.wid) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.code')"
            prop="code"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.name')"
            prop="name"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.type')"
            min-width="120"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(warehouseTypeList, row.is_futures) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('order.quantityPurchased')"
            prop="quantity"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.theQuantityToBeShipped')"
            prop="pending_quantity"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.theNumberOfShipments')"
            min-width="180"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              <el-input-number
                v-if="row.fl_warehouse_id"
                v-model="row.ship_quantity"
                :disabled="Number(row.pending_quantity) === 0"
                :min="1"
                :max="Number(row.pending_quantity) !== 0 ? parseInt(row.pending_quantity) : 100000"
              />
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.arrivalDate')"
            prop="arrival_date"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.realArrivalDate')"
            prop="real_arrival_date"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.originalPrice')"
            min-width="160"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ row.original_price }}({{ row.actual_quoted_currency_name }})
            </template>
          </el-table-column>
          <el-table-column
            :label="t('order.discountedPrice')"
            min-width="160"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ row.actual_price }}({{ row.actual_quoted_currency_name }})
            </template>
          </el-table-column>
          <el-table-column
            :label="t('order.theActualPricePaid')"
            min-width="160"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ row.actual_selling_price }}({{
                useEnumeratePicker(currentList, form?.currency ?? '')
              }})
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.brand')"
            min-width="150"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(brandList, row.brand) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.computingPower')"
            prop="hashrate"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.warranty')"
            prop="expiration_date"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <!-- 操作栏 -->
          <!-- 一级仓库的字段判断 -->
          <el-table-column fixed="right" label="操作" width="150">
            <template #default="{ row }">
              <el-button
                @click="openDeliveryDialog(row)"
                type="primary"
                size="small"
                v-if="!row.fl_warehouse_id && row.pending_quantity && row.is_futures === 0"
              >
                {{ t('order.delivery') }}
              </el-button>

              <el-button
                @click="openTransferWidDialog(row)"
                type="primary"
                size="small"
                v-if="row.pending_quantity && row.pending_quantity > 0 && row.is_futures === 0"
                v-hasPermi="['OrderManagementAdjustWarehouse']"
              >
                {{ t('order.transferWarehouse') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--    支付信息-->
        <!-- <div class="flex my-20px text-14px font-bold">支付信息</div>
        <el-table
          :data="payTableList"
          highlight-current-row
          stripe
          border
          :cell-style="{ textAlign: 'center' }"
          :header-cell-style="{ textAlign: 'center' }"
        >
          <el-table-column
            :label="t('order.paymentMethod')"
            min-width="250"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(paymentMethodList, row.pay_method) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.receivingAccountNumber')"
            prop="pay_account"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.transactionTicketNumber')"
            prop="voucher_code"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.proofOfTransfer')"
            min-width="250"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              <el-image
                v-if="row.transfer_voucher_url"
                style="width: 100px; height: 100px"
                :src="row.transfer_voucher_url"
                :preview-teleported="true"
                :zoom-rate="1.2"
                :max-scale="7"
                :min-scale="0.2"
                :preview-src-list="[row.transfer_voucher_url]"
                fit="cover"
              />
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.paymentTrackingCode')"
            prop="pay_code"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.paymentCurrency')"
            prop="pay_currency"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.paymentLinks')"
            prop="payment_url"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.paymentTime')"
            prop="pay_time"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.theAmountToBePaid')"
            prop="pay_amount"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.paymentStatus')"
            min-width="250"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(itemPayStatusList, row.pay_status) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.notes')"
            prop="notes"
            min-width="250"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.reviewers')"
            prop="reviewer"
            min-width="250"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(operatorList, row.reviewer) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.reviewTime')"
            prop="reviewer_time"
            min-width="250"
            :show-overflow-tooltip="true"
          />
        </el-table> -->
        <!--    自提信息-->
        <div v-if="form.delivery_method === 0">
          <div class="flex my-20px text-14px font-bold">自提信息</div>
          <el-table
            :data="selfPickupTableList"
            highlight-current-row
            stripe
            border
            :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }"
          >
            <el-table-column
              :label="t('order.pickupCode')"
              prop="pickup_code"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.pickUpAddress')"
              prop="pickup_address"
              min-width="400"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.theNameOfThePersonWhoPickedUpTheGoods')"
              prop="pickup_name"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.pickUpPersonSPhoneNumber')"
              prop="pickup_phone"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.passportOfThePersonPickingUpTheGoods')"
              prop="pickup_passport"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.pickUpPersonSVehicleInformation')"
              prop="pickup_vehicle"
              min-width="200"
              :show-overflow-tooltip="true"
            />
          </el-table>
        </div>
        <div v-if="form.delivery_method === 1">
          <!--    收货信息-->
          <div class="flex my-20px text-14px font-bold">收货信息</div>
          <el-table
            :data="receivingTableList"
            highlight-current-row
            stripe
            border
            :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }"
          >
            <el-table-column
              :label="t('order.consignee')"
              prop="name"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.phone')"
              prop="phone"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.email')"
              prop="email"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.zipCode')"
              prop="zip_code"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.country')"
              prop="country_name"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('dealerAssetManagement.provinceOrState')"
              prop="state"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.city')"
              prop="city_name"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.address')"
              prop="address"
              min-width="350"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.alternateAddress')"
              prop="address2"
              min-width="350"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.company')"
              prop="company"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.delivery_remark')"
              prop="delivery_remark"
              min-width="160"
              :show-overflow-tooltip="true"
            />
            <!--            <el-table-column-->
            <!--              :label="t('order.aging')"-->
            <!--              min-width="200"-->
            <!--              :show-overflow-tooltip="true"-->
            <!--            >-->
            <!--              <template #default="{ row }">-->
            <!--                {{ useEnumeratePicker(agingList, row.prescription) }}-->
            <!--              </template>-->
            <!--            </el-table-column>-->
            <!-- 操作列 -->
            <el-table-column label="操作" width="120" fixed="right" :show-overflow-tooltip="true">
              <template #default="{ row }">
                <el-button type="primary" size="small" @click="copyReceivingInfo(row)">
                  一键复制
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <!--    物流信息-->
          <div class="flex my-20px text-14px font-bold">物流信息</div>
          <el-table
            :data="logisticsTableList"
            row-key="id"
            border
            :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }"
            :tree-props="{ children: 'children' }"
            :default-expand-all="true"
          >
            <el-table-column prop="company" label="物流公司" width="200">
              <template #default="{ row }">
                <span>
                  {{ useEnumeratePicker(logisticsCompanyList, row.company) }}
                </span>
              </template>
            </el-table-column>
            <el-table-column prop="serial_number" label="发货单号" width="200" />
            <el-table-column prop="logistics_no" label="物流单号" width="200" />
            <el-table-column prop="logistics_voucher" label="物流凭证" width="200">
              <template #default="{ row }">
                <div v-if="row.logistics_voucher && row.logistics_voucher.length">
                  <el-image
                    style="width: 100px; height: 100px"
                    :src="row.logistics_voucher[0]"
                    :preview-teleported="true"
                    :zoom-rate="1.2"
                    :max-scale="7"
                    :min-scale="0.2"
                    :preview-src-list="row.logistics_voucher"
                    fit="cover"
                  />
                  <div>{{ `共${row.logistics_voucher.length}张` }}</div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="cost" label="成本" width="160">
              <template #default="{ row }">
                <div v-for="(item, index) in row.cost" :key="index">
                  <span>{{ useEnumeratePicker(operatorOptions.costing, item.type) }}:</span>
                  <span>{{ item.amount }}</span>
                  <span>{{
                    useEnumeratePicker(operatorOptions.currency, item.transaction_currency_id)
                  }}</span>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="notes" label="备注" width="140" />
            <el-table-column prop="ship_date" label="发货时间" width="200" />
            <el-table-column prop="product_code" label="商品编码" width="200" />
            <el-table-column prop="product_name" label="商品名称" width="240" />
            <el-table-column prop="warehouse_name" label="仓库" />
            <el-table-column prop="number" label="数量" width="80" />

            <!-- <el-table-column fixed="right" label="操作" width="80">
              <template #default="{ row }">
                <el-button v-if="row.id" type="primary" @click="handleDelivery(2)" size="small">
                  {{ '编辑' }}
                </el-button>
              </template>
            </el-table-column> -->
          </el-table>
          <!-- <el-table
            :data="logisticsTableList"
            highlight-current-row
            stripe
            border
            :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }"
          >
            <el-table-column
              :label="t('order.logisticsCompanies')"
              min-width="200"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                {{ useEnumeratePicker(logisticsCompanyList, row.company) }}
              </template>
            </el-table-column>
            <el-table-column
              :label="t('order.trackingNumber')"
              prop="logistics_no"
              min-width="250"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.logisticsVouchers')"
              min-width="250"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                <div v-if="row.logistics_voucher && row.logistics_voucher.length">
                  <el-image
                    style="width: 100px; height: 100px"
                    :src="row.logistics_voucher[0]"
                    :preview-teleported="true"
                    :zoom-rate="1.2"
                    :max-scale="7"
                    :min-scale="0.2"
                    :preview-src-list="row.logistics_voucher"
                    fit="cover"
                  />
                  <div>{{ `共${row.logistics_voucher.length}张` }}</div>
                </div>
              </template>
            </el-table-column>
            <el-table-column
              :label="t('order.cost')"
              prop="cost"
              min-width="200"
              :show-overflow-tooltip="true"
            />
          </el-table> -->
        </div>
      </div>
      <!--      时间线-->
      <TimeLine class="w-15%" :data="timeLineList" />
      <!--      发货弹框-->
      <DialogDelivery ref="DialogDeliveryRef" @refresh="initialize" />
      <!--商品信息发货弹框-->
      <DialogShop
        ref="DialogShopRef"
        :key="dialogKey"
        :shopInfo="shopInfo"
        :warehouseList="warehouseList"
        @refresh="goRefresh"
      />
      <!--商品调仓发货弹框-->
      <DialogTransferWid
        ref="DialogTransferWidRef"
        :key="dialogKey"
        :shopInfo="shopInfo"
        @refresh="initialize"
      />
    </div>
  </ContentDetailWrap>
</template>
<script setup lang="tsx">
import TimeLine from './components/TimeLine/index.vue'
import DialogDelivery from './components/DialogDelivery/index.vue'
import DialogShop from './components/DialogShop/index.vue'
import DialogTransferWid from './components/DialogTransferWid/index.vue'
import { ContentDetailWrap } from '@/components/ContentDetailWrap'
import { useEnumeratePicker } from '@/utils'
import { getOrderEnumApi, getDetailApi } from '@/api/order'
import { Descriptions, type DescriptionsSchema } from '@/components/Descriptions'

const { t } = useI18n()
const { push, go } = useRouter()
const { query } = useRoute()

const loading = ref<boolean>(false)
const routerParams = ref<Record<string, any>>({})
const multipleSelection = ref<any[]>([])
const DialogDeliveryRef = ref<InstanceType<typeof DialogDelivery>>()
const DialogShopRef = ref<Record<string, any>>({})
const form = ref<Record<string, any>>({})

const shopTableList = ref<Array<Record<string, any>>>([])
const payTableList = ref<Array<Record<string, any>>>([])
const selfPickupTableList = ref<Array<Record<string, any>>>([])
const receivingTableList = ref<Array<Record<string, any>>>([])
const logisticsTableList = ref<Array<Record<string, any>>>([])
const timeLineList = ref<Array<Record<string, any>>>([])

const receiptMethodList = ref<Array<Record<string, any>>>([])
const orderStatusList = ref<Array<Record<string, any>>>([])
const paymentStatusList = ref<Array<Record<string, any>>>([])
const itemPayStatusList = ref<Array<Record<string, any>>>([])
const operatorList = ref<Array<Record<string, any>>>([])

const brandList = ref<Array<Record<string, any>>>([])
const currentList = ref<Array<Record<string, any>>>([])
const warehouseList = ref<Array<Record<string, any>>>([])
const warehouseTypeList = ref<Array<Record<string, any>>>([])

const paymentMethodList = ref<Array<Record<string, any>>>([])
const agingList = ref<Array<Record<string, any>>>([])
const logisticsCompanyList = ref<Array<Record<string, any>>>([])
const reviewNodeList = ref<Array<Record<string, any>>>([])

const descriptionSchema = ref<DescriptionsSchema[]>([
  {
    field: 'id',
    label: t('common.serialNumber')
  },
  {
    field: 'user',
    label: t('order.customer')
  },
  {
    field: 'order_no',
    label: t('order.orderCode')
  },
  {
    field: 'total_amount',
    label: t('order.theTotalAmountOfTheOrder')
  },
  {
    field: 'order_status',
    label: t('order.orderStatus'),
    slots: {
      default: (data: Record<string, any>) => {
        const statusMap = {
          10: '#FFA500', // 黄色 - 待处理
          20: '#FFD700', // 黄色
          21: '#32CD32', // 绿色
          30: '#1E90FF', // 蓝色
          40: '#9370DB', // 紫色
          50: '#20B2AA', // 青色
          70: '#c8c9cc', // 红色 - 已取消
          100: '#67c23a' // 绿色 - 已完成
        }
        const color = statusMap[data.order_status] || 'var(--el-color-warning)'
        return (
          <span
            style={`color: ${color}; background-color: var(--el-color-info-light-9); font-weight: 600; font-size: 12px; padding: 5px 15px; border-radius: 4px`}
          >
            {useEnumeratePicker(orderStatusList.value, data.order_status)}
          </span>
        )
      }
    }
  },
  {
    field: 'pay_amount',
    label: t('order.theAmountToBePaid')
  },
  {
    field: 'pay_status',
    label: t('order.payStatus'),
    slots: {
      default: (data: Record<string, any>) => {
        return <span>{useEnumeratePicker(paymentStatusList.value, data.pay_status)}</span>
      }
    }
  },
  {
    field: 'delivery_method',
    label: t('order.receiptMethod'),
    slots: {
      default: (data: Record<string, any>) => {
        return <span>{useEnumeratePicker(receiptMethodList.value, data.delivery_method)}</span>
      }
    }
  }
])

const selectable = (row: Record<string, any>) =>
  [0].includes(row.is_futures) && row.fl_warehouse_id && Number(row.pending_quantity) > 0

//批量勾选
const handleSelectionChange = (val: any[]) => {
  multipleSelection.value = val
}
// 打开弹窗
const shopInfo = ref<Record<string, any>>({})

const dialogKey = ref(0)

const openDeliveryDialog = (row) => {
  shopInfo.value = row
  dialogKey.value++
  nextTick(() => {
    DialogShopRef.value!.dialogVisible = true
    DialogShopRef.value!.getData()
  })
}
const goRefresh = (shop) => {
  nextTick(() => {
    DialogDeliveryRef.value!.dialogVisible = true
    DialogDeliveryRef.value!.getDropDownBoxInfo(
      JSON.parse(JSON.stringify([shop.data])),
      JSON.parse(JSON.stringify(Object.assign({}, form.value, { shop_fl_warehouse: 1 })))
    )
  })
}
//点击发货打开发货弹框
/*
type: 1:发货 2:修改物流信息 
*/
const handleDelivery = (type: number) => {
  if (!multipleSelection.value.length && type === 1)
    return ElMessage.warning('请勾选商品信息中需要发货的商品')
  if (type === 1) {
    const wids = multipleSelection.value.map((item) => item.wid)
    if (new Set(wids).size > 1) {
      return ElMessage.warning('商品信息中需要发货的商品必须属于同一仓库')
    }
  }
  nextTick(() => {
    DialogDeliveryRef.value!.dialogVisible = true
    DialogDeliveryRef.value!.getDropDownBoxInfo(
      JSON.parse(JSON.stringify(multipleSelection.value)),
      JSON.parse(JSON.stringify(form.value))
    )
  })
}
const DialogTransferWidRef = ref()
const openTransferWidDialog = (row) => {
  shopInfo.value = row
  dialogKey.value++
  nextTick(() => {
    DialogTransferWidRef.value!.dialogVisible = true
    DialogTransferWidRef.value!.getData()
  })
}

// 一键复制收货信息
const copyReceivingInfo = (row) => {
  const entries = [
    [t('order.consignee'), row.name],
    [t('order.phone'), row.phone],
    [t('order.email'), row.email],
    [t('order.zipCode'), row.zip_code],
    [t('order.country'), row.country_name],
    [t('dealerAssetManagement.provinceOrState'), row.state],
    [t('order.city'), row.city_name],
    [t('order.address'), row.address],
    [t('order.alternateAddress'), row.address2],
    [t('order.company'), row.company]
  ]

  const info = entries
    .filter(([, value]) => value !== undefined && value !== null && String(value) !== '')
    .map(([label, value]) => `${label}: ${value}`)
    .join('\n')

  // 复制到剪贴板
  navigator.clipboard
    .writeText(info)
    .then(() => {
      ElMessage.success('收货信息已复制到剪贴板')
    })
    .catch(() => {
      // 降级方案：创建临时文本区域
      const textArea = document.createElement('textarea')
      textArea.value = info
      document.body.appendChild(textArea)
      textArea.select()
      document.execCommand('copy')
      document.body.removeChild(textArea)
      ElMessage.success('收货信息已复制到剪贴板')
    })
}
//获取枚举
const operatorOptions = ref<Record<string, any>>({})
const getDropDownBoxInfo = async () => {
  const resp = await getOrderEnumApi({ field: 'all' })
  operatorOptions.value = resp.data
  receiptMethodList.value = resp.data.delivery_method
  orderStatusList.value = resp.data.status
  paymentStatusList.value = resp.data.pay_status
  paymentMethodList.value = resp.data.pay_method
  brandList.value = resp.data.brand
  currentList.value = resp.data.currency
  warehouseList.value = resp.data.warehouse
  warehouseTypeList.value = resp.data.is_futures
  agingList.value = resp.data.prescription
  logisticsCompanyList.value = resp.data.logistics_company
  itemPayStatusList.value = resp.data.item_pay_status
  reviewNodeList.value = resp.data.review_node
  operatorList.value = resp.data.operator
}

const initialize = async () => {
  const resp = await getDetailApi((query.id as string) || '')
  form.value = resp.data
  form.value.id = query.id
  shopTableList.value = resp.data.list.flatMap((item: Record<string, any>) => [
    { ...item, ship_quantity: item.pending_quantity }
  ])
  payTableList.value = resp.data.payment
  selfPickupTableList.value = resp.data.pickup
  receivingTableList.value = resp.data.delivery
  logisticsTableList.value = resp.data.logistics
  logisticsTableList.value.forEach((item) => {
    if (item.children && !Array.isArray(item.children)) {
      item.children = [item.children]
    }
    item.logistics_voucher = item.logistics_voucher.map((file: { url: any }) => file.url)
  })
  timeLineList.value = resp.data.logger
}
onMounted(() => {
  getDropDownBoxInfo()
  initialize()
})
</script>
<style lang="less" scoped></style>
